/**
 * Created by chenma on 12/24/2016.
 */
var passUrl = [
    '/',
    '/login',
    '/getDepartmentRelationship',
    '/getDepartmentRelationshipByRegions',
    '/saveUserDeptInfo',
    '/getReports',
    '/getSoftUpdateRecords',
    '/getSoftConfig',
    '/getUserDeptInfoByOffices',
    '/getHardwareHeathChecking',
    '/saveHardwareHeathChecking',
    '/getAllSoftConfigs',
    '/getAllRegions',
    '/getAllSettings',
    '/addServiceInfo'
];
var notAllowForReadOnlyUrls = [
    '/sendAnnouncement',
    '/save',
    '/deleteDepartmentRelationship',
    '/saveDepartmentRelationship',
    '/updateDepartmentRelationship',
    '/updateSoftConfig',
    '/saveSoftConfig',
    '/deleteSoftConfig',
    '/saveAllSettings',
    '/deleteAllSettings',
    '/triggerInstallSoft',
    '/updateSettings',
    '/updateDomain'];
function AuthFilter(req, res, next) {
    var url = req.url;
    if (!!req.session.userName) {
        if (!!req.session.readOnly && notAllowForReadOnlyUrls.indexOf(url) > -1) {
            res.redirect('/logout');
        } else {
            next();
        }
    } else if (passUrl.indexOf(url) < 0) {
        res.redirect('/');
    } else {
        next();
    }
}
module.exports = AuthFilter;

